package com.bonc.rms.controller.tms;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.bonc.odk.logmanager.LogManager;
import com.bonc.rms.entity.tms.School;
import com.bonc.rms.service.tms.WastageInfoService;

@Controller
@RequestMapping(value = "/WastageInfoController")
public class WastageInfoController {
	@Autowired
	WastageInfoService wastageInfoService;



	/**
	 * 
	 * @param departmentId
	 * @return 离职员工毕业学校前十年
	 */
	@RequestMapping(value = "/WastageSchoolInfo")
	@ResponseBody
	public String getWastageSchoolInfo(Integer departmentId) {
		LogManager.Method("Int Service : WastageInfoController -> getWastageSchoolInfo");
		List<School> schoolList = new ArrayList<>();
		schoolList = wastageInfoService.getWastageSchoolInfo(departmentId);
		Map<String, Object> wastageSchoolMap = new HashMap<String, Object>();

		List<String> titleList = new ArrayList<String>();
		List<Map<String, Object>> dateList = new ArrayList<Map<String, Object>>();
		List<String> datesList = new ArrayList<String>();

		titleList.add("离职员工毕业学校");

		wastageSchoolMap.put("title", titleList);
		wastageSchoolMap.put("name1", "人数");
		List<String> sumList = new ArrayList<>();
		sumList = new ArrayList<String>();

		Map<String, Object> map = new HashMap<>();
		map.put("name", "离职员工毕业学校");
		map.put("type", "bar");

		if (schoolList == null || schoolList.size() == 0) {
			for (int i = 0; i < 10; i++) {
				datesList.add("无");
				sumList.add("0");
			}

		} else {
			for (School school : schoolList) {
				datesList.add(school.getGraduate_school());
				sumList.add(school.getSum() + "");
			}

		}
		map.put("data", sumList.toArray());
		dateList.add(map);

		wastageSchoolMap.put("date", dateList);
		wastageSchoolMap.put("dates", datesList);
		LogManager.Method("Out Service : WastageInfoController -> getWastageSchoolInfo");
		return JSON.toJSONString(wastageSchoolMap);

	}

	/**
	 * 
	 * @param departmentId
	 * @return 离职员工薪资范围
	 */
	@RequestMapping(value = "/WastageSalaryInfo")
	@ResponseBody
	public String getWastageSalaryInfo(Integer departmentId) {

		LogManager.Method("Int Service : WastageInfoController -> getWastageSalaryInfo");
		
		Map<String, String> wastageInfoMap = wastageInfoService
				.getWastageSalaryInfo(departmentId);

		Map<String, Object> wastageSalaryMap = new HashMap<String, Object>();

		List<String> titleList = new ArrayList<String>();
		List<Map<String, String>> dateList = new ArrayList<>();

		titleList.add("离职薪水范围");

		for (Map.Entry<String, String> entry : wastageInfoMap.entrySet()) {
			Map<String, String> map = new HashMap<String, String>();
			map.put("name", entry.getKey());
			map.put("value", entry.getValue());
			// dateList.add("name:"+entry.getKey()+","+"value:"+entry.getValue());
			dateList.add(map);
		}

		wastageSalaryMap.put("title", titleList);
		wastageSalaryMap.put("date", dateList);
		wastageSalaryMap.put("name1", "人数");
		LogManager.Method("Out Service : WastageInfoController -> getWastageSalaryInfo");	
		return JSON.toJSONString(wastageSalaryMap);
	}
}
